<%--
  Created by IntelliJ IDEA.
  User: 19000
  Date: 2022/8/18
  Time: 19:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
    <meta content="webkit" name="renderer">
    <link href="${pageContext.request.contextPath}/css/pintuer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/admin.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
</head>

<body>
<div class="panel admin-panel">
    <li>
        <form action="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=1" method="post">
            <input class="input" name="productName" placeholder="请输入商品名称进行搜索"
                   style="width:250px; line-height:17px;display:inline-block" type="text"/>
            <input class="button border-main icon-search" type="submit" value="搜索">
        </form>
    </li>
</div>


<table class="table table-hover text-center">
    <tr>
        <th width="10%">商品编号</th>
        <th width="15%">商品名称</th>
        <th width="20%">商品介绍</th>
        <th width="20%">商品库存</th>
        <th width="10%">商品价格</th>
        <th width="10%">上架状态</th>
        <th width="15%">操作</th>
    </tr>

    <%--查询所有--%>
    <c:if test="${page.list != null}">
        <c:forEach items="${page.list}" var="product">
            <tr>
                <td>${product.id}</td>
                <td>${product.name}</td>
                <td>${product.description}</td>
                <td>${product.stock}</td>
                <td>${product.price}</td>
                <td>
                    <c:if test="${product.status == 0}">是</c:if>
                    <c:if test="${product.status == 1}">否</c:if>
                </td>
                <td>
                    <div class="button-group">
                        <a class="button border-main"
                           href="${pageContext.request.contextPath}/product/turnToUpdateProductPage?productId=${product.id}"><span
                                class="icon-edit"></span> 修改</a>
                        <a class="button border-red" href="javascript:void(0)" onclick="return del(${product.id})"><span
                                class="icon-trash-o"></span> 删除</a>
                    </div>

                </td>
            </tr>
        </c:forEach>
    </c:if>

    <%--根据名字查询--%>
    <c:if test="${pageByCondition.list != null}">
        <c:forEach items="${pageByCondition.list}" var="product">
            <tr>
                <td>${product.id}</td>
                <td>${product.name}</td>
                <td>${product.description}</td>
                <td>${product.stock}</td>
                <td>${product.price}</td>
                <td>
                    <c:if test="${product.status == 0}">是</c:if>
                    <c:if test="${product.status == 1}">否</c:if>
                </td>
                <td>
                    <div class="button-group">
                        <a class="button border-main"
                           href="${pageContext.request.contextPath}/product/turnToUpdateProductPage?productId=${product.id}"><span
                                class="icon-edit"></span> 修改</a>
                        <a class="button border-red" href="javascript:void(0)" onclick="return del(${product.id})"><span
                                class="icon-trash-o"></span> 删除</a>
                    </div>

                </td>
            </tr>
        </c:forEach>
    </c:if>

</table>

<%--分页导航条(全部商品)--%>
<c:if test="${page.list != null}">
    <div class="pagelist">
        <a href="${pageContext.request.contextPath}/product/page?pageNum=1">首页</a>
            <%--
                如果在第一页时，点击上一页，那就直接访问第一页
                如果不在第一页时，点击上一页，那就访问上一页
            --%>
        <c:if test="${page.pageNum == 1}">
            <a href="${pageContext.request.contextPath}/product/page?pageNum=1">上一页</a>
        </c:if>
        <c:if test="${page.pageNum != 1}">
            <a href="${pageContext.request.contextPath}/product/page?pageNum=${page.prePage}">上一页</a>
        </c:if>

        <c:forEach items="${page.navigatepageNums}" var="num">
            <c:if test="${page.pageNum == num}">
                <span class="current">${num}</span>
            </c:if>
            <c:if test="${page.pageNum != num}">
                <a href="${pageContext.request.contextPath}/product/page?pageNum=${num}">${num}</a>
            </c:if>
        </c:forEach>

            <%--
                如果在最后一页时，点击下一页，那就直接访问尾页
                如果不在最后一页时，点击下一页，那就访问下一页
            --%>
        <c:if test="${page.pageNum == page.pages}">
            <a href="${pageContext.request.contextPath}/product/page?pageNum=${page.pages}">下一页</a>
        </c:if>
        <c:if test="${page.pageNum != page.pages}">
            <a href="${pageContext.request.contextPath}/product/page?pageNum=${page.nextPage}">下一页</a>
        </c:if>
            <%--pages是总页数--%>
        <a href="${pageContext.request.contextPath}/product/page?pageNum=${page.pages}">尾页</a>
    </div>
</c:if>


<%--分页导航条（条件查询）--%>
<c:if test="${pageByCondition.list != null}">
    <div class="pagelist">
        <a href="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=1">首页</a>
            <%--
                如果在第一页时，点击上一页，那就直接访问第一页
                如果不在第一页时，点击上一页，那就访问上一页
            --%>
        <c:if test="${pageByCondition.pageNum == 1}">
            <a href="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=1">上一页</a>
        </c:if>

        <c:if test="${pageByCondition.pageNum != 1}">
            <a href="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=${pageByCondition.prePage}">上一页</a>
        </c:if>

        <c:forEach items="${pageByCondition.navigatepageNums}" var="num">
            <c:if test="${pageByCondition.pageNum == num}">
                <span class="current">${num}</span>
            </c:if>
            <c:if test="${pageByCondition.pageNum != num}">
                <a href="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=${num}">
                        ${num}</a>
            </c:if>
        </c:forEach>

            <%--
                如果在最后一页时，点击下一页，那就直接访问尾页
                如果不在最后一页时，点击下一页，那就访问下一页
            --%>
        <c:if test="${pageByCondition.pageNum == page.pages}">
            <a href="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=${pageByCondition.pages}">下一页</a>
        </c:if>
        <c:if test="${pageByCondition.pageNum != page.pages}">
            <a href="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=${pageByCondition.nextPage}">下一页</a>
        </c:if>
            <%--pages是总页数--%>
        <a href="${pageContext.request.contextPath}/product/queryProductByNamePage?pageNum=${pageByCondition.pages}">尾页</a>
    </div>
</c:if>


<script type="text/javascript">
    function del(id) {
        if (confirm("您确定要删除id为" + id + "的商品吗吗?")) {
            location.href = "${pageContext.request.contextPath}/product/deleteProductById?productId=" + id;
        }
    }
</script>

</body>
</html>
